package com.itheima.d2_string;

/**
 * String 类常用方法
 */
public class StringDemo2 {
    public static void main(String[] args) {
        String s ="卢宇浩";
        //1.获取字符串的长度
        System.out.println(s.length());
        //2.提取字符串中某个索引位置出的字符
        char c =s.charAt(1);
        System.out.println(c);
        //字符串遍历
        for(int i=0;i<s.length();i++){
            char c1 =s.charAt(i);
            System.out.print(c1);
        }
        System.out.println("================================");
        //3.把字符串换成字符数组 在遍历
        char[] chs = s.toCharArray();
        for(int i=0;i<chs.length;i++){
            char c1 =chs[i];
            System.out.print(c1);
        }
        //4.判断字符串内容，内容一样就返回true
        String s1 =new String("123");
        String s2 =new String("123");
        System.out.println(s1.equals(s2));//true
        //==:基本数据类型比较的是值，引用数据类型比较的是地址值
        System.out.println(s1 == s2);//false
        //5.忽略大小写进行内容比较
        String ss1 ="zfq";
        String ss2 = "ZFQ";
        System.out.println(ss1.equals(ss2));
        System.out.println(ss1.equalsIgnoreCase(ss2));
        //6.截取字符串内容（包前不包后）
        String s3 ="Java是最好的编程语言";
        String rs = s3.substring(0,5);
        System.out.println(rs);
        String rs2 = s3.substring(5);
        System.out.println(rs2);
        System.out.println(s3);//原来的字符串不变
        System.out.println("==============================");
        //7.字符串的某个内容替换成新内容，并返回新的字符串对象给我们
        String info = "这个人是个傻逼，真的傻逼";
        String rs3 =info.replaceAll("傻逼","帅比");
        System.out.println(rs3);
        //8.判断某个字符串是否包含某个关键字
        String info2 = "Java是最好的编程语言之一，我爱Java,Java不爱我！！";
        System.out.println(info2.contains("Java"));
        System.out.println(info2.contains("Java1"));
        System.out.println(info2.contains("java"));
        //9.判断字符串是否以某个内容开头
        String rs4 = "张三丰";
        System.out.println(rs4.startsWith("张"));//true
        System.out.println(rs4.startsWith("张三"));//true
        System.out.println(rs4.startsWith("张三丰"));//true
        System.out.println(rs4.startsWith("张三2"));//false
        System.out.println("-----------------------------");
        System.out.println(rs4.endsWith("丰"));
        System.out.println(rs4.endsWith("张三"));
        System.out.println(rs4.endsWith("张三丰"));
        System.out.println(rs4.endsWith("三丰"));
        System.out.println("-----------------------------");
        //10.分割字符串
        String rs5 = "张三丰,张无忌,周芷若,赵敏";
        String[] rs6 = rs5.split(",");
        for (int i = 0; i < rs6.length; i++) {
            System.out.println(rs6[i]);
        }
    }
}
